package org.lanqiao.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.lanqiao.entity.AdminLogin;
import org.lanqiao.service.AdminLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("")
public class AdminController {
	@Autowired
	private AdminLoginService adminLoginService;
	
	/**
	 * 登录
	 * @return
	 */
	@RequestMapping("/login")
	public String Login(){
		return "login";
	}
	@RequestMapping("/showLogin")
	public String Login1(String ulogname,String ulogpsw, HttpServletRequest request) {   
		AdminLogin adminloginresult=adminLoginService.Login(new AdminLogin(ulogname,ulogpsw));
		int i =1;
		if(adminloginresult==null) {
			request.setAttribute("adminLogin", adminloginresult);
			request.setAttribute("errorMsg", "账号密码错误");
			
			return "login";
		}else{
			HttpSession session =request.getSession();
			session.setAttribute("currentadminLogin",adminloginresult);
			
			return "index";
		}	
	}
	/**
	 * 个人信息
	 */
	@RequestMapping("user/user_info")
	public ModelAndView user_info(){
		ModelAndView mav =new ModelAndView("user/user_info");
		return mav;
	}
	/**
	 *账务账号 
	 */
		@RequestMapping("account/account_list")
		public ModelAndView account_list(){
			ModelAndView mav =new ModelAndView("account/account_list");
			return mav;
		}
	
	/**
	 * 账单管理
	 */
	@RequestMapping("bill/bill_list")
	public ModelAndView bill_list(){
		ModelAndView mav =new ModelAndView("bill/bill_list"); 
		return mav;
	}
	/**
	 * 修改用户名，电话，邮箱
	 */
	@RequestMapping("/update")
	public ModelAndView update(AdminLogin currentadminLogin,HttpServletRequest request) {
		currentadminLogin.getId();
		int i = adminLoginService.update(currentadminLogin);
		ModelAndView mav =new ModelAndView("user/user_info");
		if(i>0)
			mav.addObject("currentadminLogin", currentadminLogin);
		return mav;
	}
}
